//
//  UserInfoController.m
//  QQplayground
//
//  Created by zhangxy on 2018/6/7.
//  Copyright © 2018年 zhang. All rights reserved.
//

#import "UserInfoController.h"

#import "ZZUserTopicCell.h"
#define cellIdentifier @"ZZUserTopicCell"

#import "ZZUserInfoCell.h"


#import "ZZTalkListCell.h"
#define cellIdentifierTalk @"ZZTalkListCell"

#import "TalkDetailController.h"

#import <MJRefresh.h>
#import "SettingController.h"
#import "SettingController.h"
#import "ZZShareView.h"
#import "ZZContentCommentController.h"
#import "ZZContentDetailController.h"
#import "TalkDetailController.h"

#import "MyMimiController.h"
#import "MyPublishPostController.h"
#import "ZZLetterController.h"

#import "ZZHomeTopMenu.h"
#import "ZZLeaveMessageController.h"
#import "ZZEditInfoController.h"
#import "ZZLetterDetailController.h"
#import "ReportView.h"

#import "LoginController.h"
#import "LYLPhotoTailoringViewController.h"
#import "UITableViewCell+Extra.h"

@interface UserInfoController ()<ZZTopicCellDelegate,ZZUserInfoHeaderDelegate,ImagePickerDelegate,PhotoViewControllerDelegate>{
    int page;
    int pageMimi;
    int pageTopic;
    int uploadType; // 1 背景，2头像
}

@property(nonatomic,strong)UITableView      *listTable;

@property(nonatomic,assign)UserPageDataType  pageDataType;
@property(nonatomic,strong)NSMutableArray   *listArray;
@property(nonatomic,strong)NSMutableArray   *listMimi;
@property(nonatomic,strong)NSMutableArray   *listTopic;
@property(nonatomic,strong)ZZUserInfoCell   *headerCellView;
@property(nonatomic,strong)UIScrollView    *headerScrollView;
@property(nonatomic,strong)NavTypeEntity   *checkNavType;
@property(nonatomic,strong)NSMutableArray   *navArray;

@property(nonatomic,strong)UIButton *btnLetter;

@property(nonatomic,assign)CGRect   originFrame;
@property(nonatomic,strong)UIImageView   *avatarImageView;

@property(nonatomic,strong)User *user;


@property(nonatomic,strong) ZZHomeTopMenu *headerMenu;

@property (strong, nonatomic) UIButton *btnTap1;

@property (strong, nonatomic) UIButton *btnTap2;

@property (strong, nonatomic) UIView *viewMenus;

@property (strong, nonatomic) UIImageView *imgMenuAvatar;
@property (strong, nonatomic) UILabel *labMenuName;
@property (strong, nonatomic) UIButton *backBtn;

@property (nonatomic, assign) BOOL status;;

@end

@implementation UserInfoController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //    [self setNavigationBar];
    self.navigationController.navigationBar.hidden = YES;
    
    // Do any additional setup after loading the view.
    [self createTableView];
    if (@available(iOS 11.0, *)) {
        self.listTable.contentInsetAdjustmentBehavior = UIApplicationBackgroundFetchIntervalNever;
    } else {
        self.automaticallyAdjustsScrollViewInsets = false;
        // Fallback on earlier versions
    }
    
    
    self.menuLeftButton=[UIButton buttonWithType:UIButtonTypeCustom];
    [self.menuLeftButton setFrame:CGRectMake(10, StatusBarHeight, 44, 44)];
    self.menuLeftButton.tag=BACK_BUTTON;
    [self.menuLeftButton.titleLabel setFont:ListTitleFont];
    [self.menuLeftButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.menuLeftButton setTitleColor:UIColorFromRGBAlpha(TextWhiteColor, 0.7) forState:UIControlStateHighlighted];
    [self.menuLeftButton addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.menuLeftButton.imageView setContentMode:UIViewContentModeScaleAspectFit];
    [self.menuLeftButton setImage:[UIImage imageNamed:@"btn_back_title_sel"] forState:UIControlStateNormal];
    [self.menuLeftButton setImage:[UIImage imageNamed:@"btn_back_title_sel"] forState:UIControlStateHighlighted];
    [self.menuLeftButton setAutoresizingMask:UIViewAutoresizingFlexibleRightMargin];
    [self.menuLeftButton setTitle:@"   " forState:UIControlStateNormal];
    [self.listTable addSubview:self.menuLeftButton];
    
    
    self.otherButton=[UIButton buttonWithType:UIButtonTypeCustom];
    [self.otherButton setFrame:CGRectMake(ScreenWidth-44-45, StatusBarHeight+11, 45, 22)];
    self.otherButton.tag=DOWN_BTNTAG2;
    [self.otherButton.titleLabel setFont:FontThirteen];
    [self.otherButton addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.otherButton.imageView setContentMode:UIViewContentModeScaleAspectFit];
    [self.otherButton setTitle:@"关注" forState:UIControlStateNormal];
    [self.otherButton setTitleColor:UIColorFromRGB(TextWhiteColor) forState:0];
    [self.otherButton setBackgroundColor:UIColorFromRGBAlpha(TextWhiteColor, 0.3)];
    [self.otherButton setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin];
    self.otherButton.layer.cornerRadius = 8.0f;
    self.otherButton.layer.masksToBounds = YES;
    if(![self isMySelf]){
        [self.listTable addSubview:self.otherButton];
    }
    
    _btnLetter = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.btnLetter setFrame:CGRectMake(ScreenWidth-44-55-10-45, StatusBarHeight+11, 55, 22)];
    self.btnLetter.tag=DOWN_BTNTAG1;
    [self.btnLetter.titleLabel setFont:ListTitleFont];
    [self.btnLetter setTitleColor:UIColorFromRGB(TextWhiteColor) forState:0];
    [self.btnLetter addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.btnLetter setTitle:@"私信" forState:UIControlStateNormal];
    [self.btnLetter setBackgroundColor:UIColorFromRGBAlpha(TextWhiteColor, 0.3)];
    [self.btnLetter setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin];
    self.btnLetter.layer.cornerRadius = 8.0f;
    self.btnLetter.layer.masksToBounds = YES;
    if(![self isMySelf]){
        [self.listTable addSubview:self.btnLetter];
    }
    
    self.menuRightButton=[UIButton buttonWithType:UIButtonTypeCustom];
    [self.menuRightButton setFrame:CGRectMake(ScreenWidth-34, StatusBarHeight+11, 24, 22)];
    self.menuRightButton.tag=RIGHT_BUTTON;
    [self.menuRightButton.titleLabel setFont:FontThirteen];
    [self.menuRightButton addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.menuRightButton.imageView setContentMode:UIViewContentModeScaleAspectFit];
    [self.menuRightButton setImageEdgeInsets:UIEdgeInsetsMake(5, 5, 5, 5)];
    if(![self isMySelf]){
        [self.menuRightButton setTitle:@"···" forState:UIControlStateNormal];
        [self.menuRightButton setBackgroundColor:UIColorFromRGBAlpha(TextWhiteColor, 0.3)];
    } else {
        [self.menuRightButton setBackgroundImage:[UIImage imageNamed:@"ic_person_setting"] forState:0];
    }
    [self.menuRightButton setTitleColor:UIColorFromRGB(TextWhiteColor) forState:0];
    
    [self.menuRightButton setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin];
    self.menuRightButton.layer.cornerRadius = 8.0f;
    self.menuRightButton.layer.masksToBounds = YES;
    [self.listTable addSubview:self.menuRightButton];
    
    MJRefreshBackFooter *footer = [MJRefreshBackFooter footerWithRefreshingBlock:^{
        [self loadMoreData];
    }];
    _listTable.footer = footer;
    
    
    [self createHeaderMenu];
    [_listTable reloadData];
    
    if([self isMySelf]){
        self.otherButton.hidden = YES;
    }else{
        self.otherButton.hidden = NO;
    }
}

-(BOOL)isMySelf{
    return [_user_id isEqual:[UserUtil getUser].user_id];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBarHidden = YES;
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    
    self.navigationController.navigationBar.hidden = NO;
    
}

-(void)changeConver:(UITapGestureRecognizer *) tap{
    if (![self isMySelf]){
        return;
    }
    
//    [[AlertUtil shareInstance] showSheet:@"" message:@"" cancelTitle:@"取消" titleArray:@[@"更换背景"] viewController:self confirm:^(NSInteger buttonTag) {
//        if(buttonTag == 0){
    uploadType = 1;
            [[ImagePickerUtil defaultPicker] startPickerWithController:self title:@"更换背景"];
//        }
//    }];
}


- (void)imagePickerDidFinishedWithInfo:(NSDictionary *)info image:(UIImage *) thumIamge file:(NSURL *) url type:(ImagePickerDelegateType) type{
    if(thumIamge){
        if(uploadType == 1){
            
            LYLPhotoTailoringViewController *photoVC = [[LYLPhotoTailoringViewController alloc] init];
            photoVC.oldImage = thumIamge;
            photoVC.mode = PhotoMaskViewModeSquare;
            photoVC.cropWidth = CGRectGetWidth([UIApplication sharedApplication].keyWindow.bounds);
            photoVC.cropHeight = CGRectGetWidth([UIApplication sharedApplication].keyWindow.bounds);
            photoVC.isDark = YES;
            photoVC.delegate = self;
            photoVC.lineColor = [UIColor whiteColor];
            [self openPushVC:photoVC];
            return;
        }
        
        
        NSData *data = UIImageJPEGRepresentation(thumIamge,0.3);
        NSString *api = API_UploadWallpaper;
        if(uploadType == 2){
            api = API_Setavatar;
        }
        
        [ImageUploadUtil uploadImage:data api:api param:@{@"session_uid":[UserUtil getUser].user_id} callback:^(NSString *imageurl, NSDictionary *videoDict, NSString *message) {
            NSLog(@"%@",videoDict);
           
            if(videoDict){
                if(self->uploadType == 2){
                    self->_user.user_avatar = videoDict[@"image_url"];
                    
                    [self->_headerCellView dataToView:self->_user with:self->_pageDataType];
                }else{
                    [NetworkUtil POST:API_Setwallpaper parameters:@{@"session_uid":[UserUtil getUser].user_id,@"wallpaper_id":convertToString(videoDict[@"wallpaper_id"])} success:^(id responseObject, NSDictionary *dict) {
                        NSLog(@"%@",dict);
                        self->_user.wallpaper_url = dict[@"data"][@"wallpaper_info"][@"wallpaper_url"];
                        
                        [self.avatarImageView sd_setImageWithURL:[NSURL URLWithString:convertToString(self->_user.wallpaper_url)]];
                        
                    } failure:^(NSError *error, NSString *message) {
                         [PopUtil showMessage:message];
                    }];
                }
            }else{
                [PopUtil showMessage:message];
            }
                
        }];
    }
}

#pragma mark - photoViewControllerDelegate
- (void)imageCropperDidCancel:(LYLPhotoTailoringViewController *)cropperViewController
{
    [cropperViewController.navigationController popViewControllerAnimated:YES];
}

- (void)imageCropper:(LYLPhotoTailoringViewController *)cropperViewController didFinished:(UIImage *)editedImage dict:(id) obj
{
    [cropperViewController.navigationController popViewControllerAnimated:YES];
    
    NSDictionary *dict = obj;
    
    NSLog(@"%@",dict);
    self->_user.wallpaper_url = dict[@"data"][@"wallpaper_info"][@"wallpaper_url"];
    
    [self.avatarImageView sd_setImageWithURL:[NSURL URLWithString:convertToString(self->_user.wallpaper_url)]];
    
    [self.avatarImageView setImage:editedImage];
}


-(void)buttonClick:(UIButton *) sender{
    if (![UserUtil getUser].isOnline && sender.tag != self.menuLeftButton.tag){
        [self showLogin];
        return;
    }
    [super buttonClick:sender];
    if(sender.tag == RIGHT_BUTTON){
        if (![UserUtil getUser].isOnline){
            [[ZZCoreTools getCoreTools] showLogin:self];
            return;
        }
        
        if([self isMySelf]){
            ZZEditInfoController *vc = [[ZZEditInfoController alloc] init];
            [vc setZZCommitResult:^(int code, NSString *message) {
                if(code == 0){
                    [self getUesrInfo];
                }else{
                    [PopUtil showMessage:message];
                }
            }];
            vc.tempUser = self.user;
            [self openPushVC:vc];
        }else{
            [[AlertUtil shareInstance] showSheet:nil message:nil cancelTitle:@"取消" titleArray:@[@"拉黑",@"举报"] viewController:self confirm:^(NSInteger buttonTag) {
                if(buttonTag == 0){
                    // 拉黑
                    [NetworkUtil POST:API_Addblack parameters:@{@"black_user_id":self->_user_id,
                                                       @"session_uid":[UserUtil getUser].user_id}
                              success:^(id responseObject, NSDictionary *dict) {
                                  [PopUtil showMessage:dict[@"msg"]];
                              } failure:^(NSError *error, NSString *message) {
                                  [PopUtil showMessage:convertToString(message)];
                              }];
                    
                }else if(buttonTag == 1){
                    // 举报
                    ReportView *report = [[ReportView alloc] initWithShareType:self];
                    report.mapping_id = _user.user_id;
                    report.mapping_uid = _user_id;
                    report.report_type = @"user";
                    [report show];
                }
            }];
        }
    }
    
    // 私信
    if(sender.tag == DOWN_BTNTAG1){
        if([self isMySelf]){
            ZZLetterController *vc = [[ZZLetterController alloc] init];
            [self openPushVC:vc];
        }else{
            MessageEntity *model=[MessageEntity new];
            model.user_info = _user;
            ZZLetterDetailController *vc = [[ZZLetterDetailController alloc] init];
            vc.model = model;
            [self openPushVC:vc];
        }
    }
    
    // 关注
    if(sender.tag == DOWN_BTNTAG2){
        NSString *url = API_Addfollow;
        if([_user.user_relation intValue] == 1){
            url = API_Delfollow;
        }
        [NetworkUtil POST:url parameters:@{@"user_id":_user_id,
                                           @"session_uid":[UserUtil getUser].user_id}
                  success:^(id responseObject, NSDictionary *dict) {
                      if([_user.user_relation intValue] == 1){
                          _user.user_relation = @"0";
                      }else{
                          _user.user_relation = @"1";
                      }
                      [self.otherButton setTitle:@"已关注" forState:UIControlStateNormal];
                  } failure:^(NSError *error, NSString *message) {
                      [PopUtil showMessage:convertToString(message)];
                      
                  }];
        
    }
}

-(void)createTableView{
    page = 1;
    pageTopic = 1;
    pageMimi  = 1;
    _status = NO;
    
    _listArray = [[NSMutableArray alloc] init];
    _listMimi = [[NSMutableArray alloc] init];
    _listTopic = [[NSMutableArray alloc] init];
    _listTable = [self.view createTableView:self cell:cellIdentifier];
    [_listTable registerNib:[UINib nibWithNibName:cellIdentifierTalk bundle:nil] forCellReuseIdentifier:cellIdentifierTalk];
 
    [_listTable setFrame:self.view.bounds];
    
    [_listTable setBackgroundColor:UIColor.clearColor];
    
    if (iOS7) {
        _listTable.backgroundView = nil;
    }
    _listTable.userInteractionEnabled = YES;
    
    
    [_listTable setSeparatorColor:LINE_COLOR];
    [_listTable setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    
    _listTable.tableHeaderView = [self headerView];
    [self setTableSeparatorInset];
    
//    MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
//        [self loadBegin];
//    }];
//    _listTable.header = header;
    
    if([self isMySelf]){
     
        _user = [UserUtil getUser];
    }else{
        _user = [User new];
        _user.user_id = _user_id;
    }
    
    [self getChannelListByNetWork];
    
    [self getUesrInfo];
    
    _pageDataType = UserPageDataSucai;
    
    [self loadBegin];
}

- (UIView *)headerView
{
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 354 + NavBarHeight)];
    
    headerView.userInteractionEnabled = YES;
    
   
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(changeConver:)];
//    [self.avatarImageView addGestureRecognizer:tap];
    [headerView addGestureRecognizer:tap];
    
    if(ZC_iPhoneX){
        _headerCellView = [[NSBundle mainBundle]loadNibNamed:@"ZZUserInfoCell" owner:nil options:nil].firstObject;
    }else{
        _headerCellView = [[NSBundle mainBundle]loadNibNamed:@"ZZUserInfoCell" owner:nil options:nil].firstObject;
    }
    [_headerCellView setFrame:CGRectMake(0, NavBarHeight, ScreenWidth, 354)];
    _headerCellView.delegate = self;
    [_headerCellView dataToView:_user with:self->_pageDataType];
    [headerView addSubview:_headerCellView];
    
    [headerView setFrame:CGRectMake(0, 0, ScreenWidth, CGRectGetMaxY(_headerCellView.frame) - 1)];
    
    self.originFrame = CGRectMake(0, 0,headerView.bounds.size.width, headerView.bounds.size.height + 98);
    
    self.headerScrollView = [[UIScrollView alloc] initWithFrame:self.originFrame];
    //    [headerView addSubview:self.headerScrollView];
    [self.view insertSubview:self.headerScrollView atIndex:0];
    self.headerScrollView.userInteractionEnabled = YES;
    
    self.avatarImageView = [[UIImageView alloc] initWithFrame:self.originFrame];
    self.avatarImageView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    self.avatarImageView.contentMode = UIViewContentModeScaleAspectFill;
    [self.avatarImageView sd_setImageWithURL:[NSURL URLWithString:convertToString(_user.wallpaper_url)] placeholderImage:[UIImage imageNamed:@"base_bg.jpg"]];
    
    self.avatarImageView.userInteractionEnabled = YES;
    [self.headerScrollView addSubview:self.avatarImageView];
    
    [self.headerScrollView setFrame:self.originFrame];
    [self.avatarImageView setFrame:self.originFrame];
    
    return headerView;
}

//设置图片透明度
- (UIImage *)imageByApplyingAlpha:(CGFloat)alpha  image:(UIImage*)image
{
    UIGraphicsBeginImageContextWithOptions(image.size, NO, 0.0f);
    
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    
    CGRect area = CGRectMake(0, 0, image.size.width, image.size.height);
    
    CGContextScaleCTM(ctx, 1, -1);
    
    CGContextTranslateCTM(ctx, 0, -area.size.height);
    
    CGContextSetBlendMode(ctx, kCGBlendModeMultiply);
    
    CGContextSetAlpha(ctx, alpha);
    
    CGContextDrawImage(ctx, area, image.CGImage);
    
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    return newImage;
}
- (UIImage *)colorizeImage:(UIImage *)baseImage withBackgroundColor:(UIColor *)theColor {
    
    UIGraphicsBeginImageContext(baseImage.size);
    
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    
    CGRect area = CGRectMake(0, 0, baseImage.size.width, baseImage.size.height);
    
    CGContextScaleCTM(ctx, 1, -1);
    
    CGContextTranslateCTM(ctx, 0, -area.size.height);
    
    CGContextSaveGState(ctx);
    
    [theColor set];
    
    CGContextFillRect(ctx, area);
    
    CGContextRestoreGState(ctx);
    
    CGContextSetBlendMode(ctx, kCGBlendModeMultiply);
    
    CGContextDrawImage(ctx, area, baseImage.CGImage); //改变背景
    
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    return newImage;
    
}


-(void)getUesrInfo{
    [NetworkUtil POST:API_UserInfo parameters:@{@"user_id":convertToString(_user_id),@"is_all":@"1"} success:^(id responseObject, NSDictionary *dict) {
        self.user = [[User alloc] initWithDictionary:dict[@"data"]];
        [self.listTable reloadData];
        if([self.user.user_relation boolValue]){
            [self.otherButton setTitle:@"已关注" forState:UIControlStateNormal];
//            [self.otherButton setBackgroundColor:UIColorFromRGB(BgTitleColor)];
        }else{
            [self.otherButton setTitle:@"关注" forState:UIControlStateNormal];
//            [self.otherButton setBackgroundColor:UIColorFromRGB(TextWhiteColor)];
        }
        if([self isMySelf]){
            self.user.isOnline = YES;
            [UserUtil saveUser:self.user];
        }
        
        if([self.user.is_vip intValue] == 1){
            self.originFrame = self.view.bounds;
            _listTable.alpha = 0.9f;
//            [_listTable setBackgroundColor:UIColor.clearColor];
            [_listTable setBackgroundColor:UIColorFromRGBAlpha(TextBlackColor, 0.1)];
            
        }
        [self.headerScrollView setFrame:self.originFrame];
        [self.avatarImageView setFrame:self.originFrame];
        
        [_headerCellView dataToView:_user with:self->_pageDataType];

        
        [_imgMenuAvatar sd_setImageWithURL:[NSURL URLWithString:self.user.user_avatar] placeholderImage:[UIImage imageNamed:@"default_image"]];
        [self.labMenuName setText:convertToString(self.user.user_name)];
        
        [self.avatarImageView sd_setImageWithURL:[NSURL URLWithString:convertToString(_user.wallpaper_url)] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
            if(image){
                [self.avatarImageView setImage:[self colorizeImage:image withBackgroundColor:UIColorFromRGBAlpha(TextBlackColor, 0.2)]];
            }else{
                [self.avatarImageView setImage:[UIImage imageNamed:@"base_bg.jpg"]];
            }
        }];
        
    } failure:^(NSError *error, NSString *message) {
        [PopUtil showMessage:message positionType:PopPositionTypeMiddle];
    }];
}

-(void)loadBegin{
    //    [_listArray removeAllObjects];
    [self loadMoreData];
}


/**
 加载更多
 */
-(void)loadMoreData{
    DLog(@"----------------");
    
    if(_pageDataType == UserPageDataSucai){
        NSString *navType = @"all";
        if(_checkNavType){
            navType = _checkNavType.nav_type;
        }
        
        [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        NSDictionary *p = @{@"user_id":convertToString(_user_id),
                            @"nav_type":convertToString(navType),
                            @"page":convertIntToString(page),
                            @"page_size":@"20"
                            };
        [NetworkUtil POST:API_GetUserHomeList parameters:p success:^(id responseObject,NSDictionary *dictionary) {
            DLog(@"API_GetUserHomeList");
            
            [MBProgressHUD hideHUDForView:self.view animated:YES];
            if([self.listTable.header isRefreshing]){
                [self.listTable.header endRefreshing];
            }
            if([self.listTable.footer isRefreshing]){
                [self.listTable.footer endRefreshing];
            }
            if(self->page == 1){
                [self.listArray removeAllObjects];
            }
            
            
            NSArray *arr = dictionary[@"data"][@"list"];
            for(NSDictionary *item in arr){
                [self.listArray addObject:[[ZZHomeTopicEntity alloc] initWithDictionary:item]];
            }
            
            self.status = (self.listArray.count==0);
            
            DLog(@"status:%d", self.status);
            
            [self.listTable reloadData];
            if([dictionary[@"data"][@"page"] intValue] < [dictionary[@"data"][@"pages"] intValue]){
                self->page = [dictionary[@"data"][@"page"] intValue] + 1;
            }
            
        } failure:^(NSError *error,NSString *message) {
            DLog(@"API_GetUserHomeList -- error");
            if([self.listTable.header isRefreshing]){
                [self.listTable.header endRefreshing];
            }
            self.status = (self.listArray.count==0);
            [self.listTable reloadData];
            
            [MBProgressHUD hideHUDForView:self.view animated:YES];
        }];
    } else if(_pageDataType == UserPageDataTopic){
        [NetworkUtil POST:API_GetForumthreadlist parameters:@{@"user_id":convertToString(_user_id),@"page":convertIntToString((int)pageTopic)} success:^(id responseObject, NSDictionary *dictionary) {
            DLog(@"API_GetForumthreadlist");
            [MBProgressHUD hideHUDForView:self.view animated:YES];
            if([self.listTable.header isRefreshing]){
                [self.listTable.header endRefreshing];
            }
            if([self.listTable.footer isRefreshing]){
                [self.listTable.footer endRefreshing];
            }
            if(self->pageTopic == 1){
                [self.listTopic removeAllObjects];
            }
            NSArray *arr = dictionary[@"data"][@"list"];
            for(NSDictionary *item in arr){
                [self.listTopic addObject:[[ForumEntity alloc] initWithDictionary:item]];
            }
            self.status = (self.listArray.count==0);
            
            DLog(@"status:%d", self.status);
            [self.listTable reloadData];
            if([dictionary[@"data"][@"page"] intValue] < [dictionary[@"data"][@"pages"] intValue]){
                self->pageTopic = [dictionary[@"data"][@"page"] intValue] + 1;
            }
        } failure:^(NSError *error, NSString *message) {
            DLog(@"API_GetForumthreadlist -- error");

            [MBProgressHUD hideHUDForView:self.view animated:YES];
            if(self->pageTopic == 1){
                [self.listTopic removeAllObjects];
                self.status = (self.listArray.count==0);
                 [self.listTable reloadData];
            }
        }];
    }
}

/**
 加载更多
 */
-(void)getChannelListByNetWork{
    
    [NetworkUtil POST:API_GetNavList parameters:@{} success:^(id responseObject, NSDictionary *dict) {
        
//        DLog(@"dict:------------%@", dic);
        NSArray *arr = dict[@"data"];
        self.navArray = [[NSMutableArray alloc] init];
        NavTypeEntity *model = [NavTypeEntity new];
        model.nav_type = @"all";
        model.nav_name = @"全部";
        model.nav_id = @"0";
        [self.navArray addObject:model];
        for (NSDictionary *item in arr) {
            NavTypeEntity *model = [[NavTypeEntity alloc] initWithDictionary:item];
            [self.navArray addObject:model];
        }
//        [self.headerCellView setList_now:self.navArray];
        
        NSMutableArray *arrList = [[NSMutableArray alloc] init];
        for (NavTypeEntity *item in _navArray) {
            [arrList addObject:item.nav_name];
        }
        if(_headerMenu==nil){
            _headerMenu = [[ZZHomeTopMenu alloc] initWithFrame:CGRectMake(10, 0, ScreenWidth-20,44) array:arrList textColor:UIColorFromRGB(Text6Color) checkColor:UIColorFromRGB(BgTitleColor) result:^(NSInteger tag, NSString *title) {
                self->_checkNavType = _navArray[tag - 1];
                [self loadBegin];
            }];
        }
    } failure:^(NSError *error, NSString *message) {
        
    }];
}



#pragma mark ---- UIScrollView Delegate Method ----
- (void) scrollViewDidScroll:(UIScrollView *)scrollView {
    CGPoint offset = scrollView.contentOffset;
    
    if (offset.y < 0) {
        CGFloat delta = 0.0f;
        CGRect rect = self.originFrame;
        delta = fabs(MIN(0.0f, offset.y));
//        rect.origin.y -= delta;
        rect.size.height += delta;
        self.headerScrollView.frame = rect;
        _listTable.tableHeaderView.clipsToBounds = NO;
        
        _imgMenuAvatar.alpha = 0.0f;
        _labMenuName.alpha = 0.0f;
        _backBtn.alpha = 0.0f;
    }else {
        CGRect frame = self.headerScrollView.frame;
        if([_user.is_vip intValue] == 0){
            if(frame.size.height - offset.y > 98){
                frame.origin.y = -offset.y;
            }
        }
        self.headerScrollView.frame = frame;
        _listTable.tableHeaderView.clipsToBounds = YES;
//        self.avatarImageView.alpha = (frame.size.height - offset.y) / frame.size.height * 0.6 + 0.6;
        
        if((offset.y - 60) - _headerCellView.frame.size.height){
            CGFloat alpha = (offset.y - 60)/60;
            if(alpha > 1){
                alpha = 1.0f;
            }
            _imgMenuAvatar.alpha = alpha;
            _labMenuName.alpha = alpha;
            _backBtn.alpha = alpha;
        } else{
            _imgMenuAvatar.alpha = 0.0f;
            _labMenuName.alpha = 0.0f;
            _backBtn.alpha = 0.0f;
        }
    }
    
//    CGFloat sectionHeaderHeight = 44;
//    if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
//        scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
//    } else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
//        scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
//    }
    
    
    [_listTable.visibleCells enumerateObjectsUsingBlock:^(__kindof UITableViewCell * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        // cell和section覆盖的高度 = 需要剪去的高度 20是contentInset， 100是sectionHeight，再减去cell的y
        CGFloat cut = 98;
        if(_pageDataType == UserPageDataTopic){
            cut = 54;
        }
        CGFloat hideCellHeight = scrollView.contentOffset.y + cut - obj.frame.origin.y;
        
        CGRect maksFrame = obj.bounds;
        
        if (hideCellHeight > 0 && hideCellHeight <= obj.frame.size.height) {
            maksFrame =  CGRectMake(0, hideCellHeight, obj.frame.size.width, obj.frame.size.height - hideCellHeight);
        } else if (hideCellHeight > obj.frame.size.height) {
            maksFrame = CGRectZero;
        }
        [obj clipOutSideCellWhenUnderTransparencySectionSetMaskFrame:maksFrame];
        
    }];
}




-(void)onHeaderCellItemClick:(ZZUserInfoHeaderType)type obj:(id)senderObj{
    DLog(@"type:---------%ld", type);
    
    if(type == ZZHeaderTypeOpenVC){
        [self openPushVC:senderObj];
    }
    
    if(type == ZZHeaderTypeZan){
        if (![UserUtil getUser].isOnline){
            [[ZZCoreTools getCoreTools] showLogin:self];
            return;
        }
        
        NSString *url = API_Userlikemember;
        if([_user.user_is_like intValue] == 1){
            url = API_Usercanceluserlike;
        }
        [NetworkUtil POST:url parameters:@{@"user_id":_user.user_id,
                                           @"session_uid":[UserUtil getUser].user_id}
                  success:^(id responseObject, NSDictionary *dict) {
                      _user.user_like = dict[@"data"][@"count"];
                      if([_user.user_is_like intValue] == 1){
                          _user.user_is_like = @"0";
                      }else{
                          _user.user_is_like = @"1";
                      }
                      [self.listTable reloadData];
                  } failure:^(NSError *error, NSString *message) {
                      [PopUtil showMessage:convertToString(message)];
                      
                  }];
    }
    if(type == ZZHeaderTypeMimi){
        MyMimiController *vc = [[MyMimiController alloc] init];
        [self openPushVC:vc];
    }
    if(type == ZZHeaderTypeSucai){
        _pageDataType = UserPageDataSucai;
        [self loadBegin];
        
        if(self.originFrame.size.height != self.view.bounds.size.height){
            self.originFrame = CGRectMake(0, 0,ScreenWidth, CGRectGetMaxY(_headerCellView.frame) - 1 + 98.0);
            [self.headerScrollView setFrame:self.originFrame];
            [self.avatarImageView setFrame:self.originFrame];
        }
    }
    
    if(type == ZZHeaderTypeTiezi){
        _pageDataType = UserPageDataTopic;
        [self loadBegin];
//        MyPublishPostController *vc = [[MyPublishPostController alloc] init];
//        [self openPushVC:vc];
        
        if(self.originFrame.size.height != self.view.bounds.size.height){
            self.originFrame = CGRectMake(0, 0,ScreenWidth, CGRectGetMaxY(_headerCellView.frame) - 1 + 54.0);
            [self.headerScrollView setFrame:self.originFrame];
            [self.avatarImageView setFrame:self.originFrame];
        }
       
    }
    
    if(type == ZZHeaderTypeChangeAvatar){
        if (![self isMySelf]){
            return;
        }
        
        uploadType = 2;
        [[ImagePickerUtil defaultPicker] startPickerWithController:self title:@"更换头像"];
    }
}

-(void)onMenuClick:(NSInteger)tag obj:(id)senderObj{
    DLog(@"tag:----------%ld", tag);
    
    _checkNavType = _navArray[tag - 1];
    [self loadBegin];
    
    
}


-(void)onCellItemClick:(ZZTopicCellClickType)type obj:(id)senderObj{
    if(type == ZZClickReport){
        if (![UserUtil getUser].isOnline){
            [[ZZCoreTools getCoreTools] showLogin:self];
            return;
        }
        
        ForumEntity *topic = senderObj;
        ReportView *report = [[ReportView alloc] initWithShareType:self];
        report.mapping_id = topic.thread_id;
        report.mapping_uid = topic.user_info.user_id;
        report.report_type = @"bbs";
        [report show];
    }
    if(type == ZZClickAttentUser){
        if (![UserUtil getUser].isOnline){
            [[ZZCoreTools getCoreTools] showLogin:self];
            return;
        }
        
        ForumEntity *topic = senderObj;
        NSString *url = API_Addfollow;
        if([topic.user_info.user_relation intValue] == 1){
            url = API_Delfollow;
        }
        [NetworkUtil POST:url parameters:@{@"user_id":topic.user_info.user_id,
                                           @"session_uid":[UserUtil getUser].user_id}
                  success:^(id responseObject, NSDictionary *dict) {
                      if([topic.user_info.user_relation intValue] == 1){
                          topic.user_info.user_relation = @"0";
                      }else{
                          topic.user_info.user_relation = @"1";
                      }
                      [self.listTable reloadData];
                  } failure:^(NSError *error, NSString *message) {
                      [PopUtil showMessage:convertToString(message)];
                      
                  }];
    }else if(type == ZZClickDel){
        [[AlertUtil shareInstance] showAlert:@"确定删除吗？" message:nil cancelTitle:@"取消" titleArray:@[@"删除"] viewController:self confirm:^(NSInteger buttonTag) {
            if(buttonTag == 0){
                if([senderObj isKindOfClass:[ZZHomeTopicEntity class]]){
                    ZZHomeTopicEntity *topic = senderObj;
                    NSString *api = API_deleteinfoTopic(topic.nav_type);
                    if([@"skin" isEqual:topic.nav_type]){
                        api = API_deleteinfoTopic(@"skins");
                    }
                    [NetworkUtil POST:api parameters:@{@"session_uid":[UserUtil getUser].user_id,@"id":convertIntToString((int)topic.t_id)} success:^(id responseObject, NSDictionary *dict) {
                        [_listArray removeObject:topic];
                        [_listTable reloadData];
                    } failure:^(NSError *error, NSString *message) {
                        
                    }];
                }else{
                    ForumEntity *topic = senderObj;
                    NSString *api = API_deleteinfoTopic(@"forum");
                    
                    [NetworkUtil POST:api parameters:@{@"session_uid":[UserUtil getUser].user_id,@"id":convertToString(topic.thread_id)} success:^(id responseObject, NSDictionary *dict) {
                        [_listTopic removeObject:topic];
                        [_listTable reloadData];
                    } failure:^(NSError *error, NSString *message) {
                        
                    }];
                }
            }
        }];
    }else{
        [ZZCoreTools sucaiListenerImpl:senderObj type:type page:self refresh:_listTable];
    }
}

#pragma mark UITableView delegate Start
// 返回section数
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

// 返回section高度
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if(_pageDataType == UserPageDataTopic){
        return 54.0f;
    }
    return 98.0f;
}

// 返回section 的View
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 34)];
    [headerView setBackgroundColor:UIColor.clearColor];
    [headerView addSubview:_viewMenus];

    if(section == 0 && _pageDataType != UserPageDataTopic){
        [_headerCellView dataToView:_user with:self->_pageDataType];
        NSMutableArray *arrList = [[NSMutableArray alloc] init];
        for (NavTypeEntity *item in _navArray) {
            [arrList addObject:item.nav_name];
        }
        if(_headerMenu!=nil){
            [headerView setFrame:CGRectMake(0, 0, ScreenWidth, 78)];
            
            UIView *bView = [[UIView alloc] initWithFrame:CGRectMake(0, 54, ScreenWidth, 44)];
            [bView setBackgroundColor:UIColor.whiteColor];
            [bView addSubview:_headerMenu];
            
            [headerView addSubview:bView];
        }
    }
    headerView.clipsToBounds = YES;
    
    return headerView;
}

// 返回section下得行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (self.status) {
        return 1;
    }
    
    if(_pageDataType == UserPageDataTopic){
        return _listTopic.count;
    }
    return _listArray.count;
}

// cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.status) {
        DefaultCell *cell = [[DefaultCell alloc] init];
        NSString *tip = (_pageDataType == UserPageDataSucai ? Unpublish_material : Unpublish_invitation);

        [cell.labText setText:tip];
        return cell;
    }
    
    if(_pageDataType == UserPageDataSucai){
        ZZUserTopicCell *cell = (ZZUserTopicCell*)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
        if (cell == nil) {
           
            cell = [[ZZUserTopicCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        }
//        cell.imgAvatar.hidden = YES;
//        cell.labName.hidden = YES;
//        cell.btnLevel.hidden = YES;
//        cell.btnVip.hidden = YES;
//        CGRect tf1 = cell.labTime.frame;
//        tf1.origin = cell.imgAvatar.origin;
//        cell.labTime.frame = tf1;
//
//        CGRect tf2 = cell.labType.frame;
//        tf2.origin = cell.labName.origin;
//        cell.labType.frame = tf2;
        if([self isMySelf]){
            cell.btnDel.hidden = NO;
        }
        cell.delegate = self;
        [cell dataToView:[_listArray objectAtIndex:indexPath.row]];
        return cell;
    }else{
        ZZTalkListCell *cell = (ZZTalkListCell*)[tableView dequeueReusableCellWithIdentifier:cellIdentifierTalk];
        if (cell == nil) {
            cell = [[ZZTalkListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifierTalk];
        }
        if([self isMySelf]){
            cell.btnDel.hidden = NO;
        }
        cell.delegate = self;
        [cell dataToView:_listTopic[indexPath.row]];
        return cell;
    }
}



// 是否显示删除功能
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
    return NO;
}

// 删除清理数据
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    editingStyle = UITableViewCellEditingStyleDelete;
}


// table 行的高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.status) {
        return ScreenHeight - 354 - NavBarHeight;
    }
    
    
    //    return 70.0f;
    UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
    return cell.frame.size.height;
}

// table 行的点击事件
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    DLog(@"didSelectRowAtIndexPath");
    
    
    //壁纸
    
    //    VipModel *model=[_listArray objectAtIndex:indexPath.section];
    if(_pageDataType == UserPageDataSucai){
        DLog(@"------------------1");
        ZZHomeTopicEntity *model=[_listArray objectAtIndex:indexPath.row];
        ZZContentDetailController *vc = [[ZZContentDetailController alloc] init];
        vc.entity = model;
        [self openPushVC:vc];
    }else{
        DLog(@"------------------2");
        ForumEntity *model=[_listTopic objectAtIndex:indexPath.row];
        TalkDetailController *vc = [[TalkDetailController alloc] init];
        vc.model = model;
        [self openPushVC:vc];
    }
    
    
    
}


//设置分割线间距
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    if((indexPath.section+1) < _listArray.count){
        UIEdgeInsets inset = UIEdgeInsetsMake(0, 10, 0, 0);
        if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
            [cell setSeparatorInset:inset];
        }
        
        if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
            [cell setLayoutMargins:inset];
        }
    }
}

-(void)viewDidLayoutSubviews{
    [self setTableSeparatorInset];
}
#pragma mark UITableView delegate end

/**
 *  设置UITableView分割线空隙
 */
-(void)setTableSeparatorInset{
    UIEdgeInsets inset = UIEdgeInsetsMake(0, 10, 0, 0);
    if ([_listTable respondsToSelector:@selector(setSeparatorInset:)]) {
        [_listTable setSeparatorInset:inset];
    }
    
    if ([_listTable respondsToSelector:@selector(setLayoutMargins:)]) {
        [_listTable setLayoutMargins:inset];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
-(void)showLogin{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:Unlogin_tip message:nil preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *cancle = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil];
    UIAlertAction *login = [UIAlertAction actionWithTitle:@"登录" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        LoginController *loginVC = [[LoginController alloc] init];
        [self addChildViewController:loginVC];
        [self.navigationController pushViewController:loginVC animated:YES];
    }];
    [alert addAction:cancle];
    [alert addAction:login];
    [self presentViewController:alert animated:YES completion:nil];
}


-(void) createHeaderMenu{
    if(_viewMenus){
        return;
    }
    _viewMenus = [[UIView alloc] initWithFrame:CGRectMake(0, 20, ScreenWidth, 35)];
    [_viewMenus setBackgroundColor:UIColor.clearColor];
    
    _backBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    [_backBtn setFrame:CGRectMake(10, 0, 44, 23)];
    _backBtn.tag=BACK_BUTTON;
    [_backBtn.titleLabel setFont:ListTitleFont];
    [_backBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_backBtn setTitleColor:UIColorFromRGBAlpha(TextWhiteColor, 0.7) forState:UIControlStateHighlighted];
    [_backBtn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    [_backBtn.imageView setContentMode:UIViewContentModeScaleAspectFit];
    [_backBtn setImage:[UIImage imageNamed:@"btn_back_title_sel"] forState:UIControlStateNormal];
    [_backBtn setImage:[UIImage imageNamed:@"btn_back_title_sel"] forState:UIControlStateHighlighted];
    [_backBtn setAutoresizingMask:UIViewAutoresizingFlexibleRightMargin];
    [_backBtn setTitle:@" " forState:UIControlStateNormal];
    [_backBtn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    [_viewMenus addSubview:_backBtn];
    
    _imgMenuAvatar = [self createImageView];
    [_imgMenuAvatar setFrame:CGRectMake(54, 0, 23, 23)];
    _imgMenuAvatar.layer.cornerRadius = 11.5f;
    _imgMenuAvatar.layer.masksToBounds = YES;
    [_imgMenuAvatar sd_setImageWithURL:[NSURL URLWithString:self.user.user_avatar] placeholderImage:[UIImage imageNamed:@"default_image"]];
    
    [_viewMenus addSubview:_imgMenuAvatar];
    
    _labMenuName = [self createLabel];
    [_labMenuName setFrame:CGRectMake(84, 0, ScreenWidth - 84 - 66*2, 21)];
    [_labMenuName setText:convertToString(self.user.user_name)];
    [_labMenuName setTextColor:UIColorFromRGB(TextWhiteColor)];
    [_labMenuName setFont:FontFiftent];
    [_viewMenus addSubview:_labMenuName];
    
    _btnTap1 = [self createButton];
    [_btnTap1 setFrame:CGRectMake(ScreenWidth - 66*2 + 11, 0, 66, 24)];
    [_viewMenus addSubview:_btnTap1];
    
    _imgMenuAvatar.alpha = 0.0f;
    _labMenuName.alpha = 0.0f;
    _backBtn.alpha = 0.0f;
    
    
    _btnTap2 = [self createButton];
    [_btnTap2 setFrame:CGRectMake(ScreenWidth - 66, 0, 66, 24)];
    [_viewMenus addSubview:_btnTap2];
    
    [_btnTap1 setTintColor:UIColorFromRGB(TextWhiteColor)];
    [_btnTap1 setBackgroundColor:UIColor.clearColor];
    [_btnTap1 setBackgroundImage:[UIImage imageNamed:@"素材"]  forState:UIControlStateSelected];
    [_btnTap1 setTitleColor:UIColorFromRGB(BgTitleColor) forState:UIControlStateSelected];
    [_btnTap1 setTitleColor:UIColorFromRGB(TextWhiteColor) forState:UIControlStateNormal];
    [_btnTap1.titleLabel setFont:ListElevenFont];
    [_btnTap1 setTitle:@"素材" forState:0];
    [_btnTap1 setImage:[UIImage imageNamed:@"素材 切换 copy"] forState:UIControlStateSelected];
    [_btnTap1 setImage:[UIImage imageNamed:@"素材 切换"] forState:UIControlStateNormal];
    [_btnTap1 addTarget:self action:@selector(tapClick:) forControlEvents:UIControlEventTouchUpInside];
    
    [_btnTap2 setTintColor:UIColorFromRGB(BgTitleColor)];
    [_btnTap2 setBackgroundColor:UIColor.clearColor];
    [_btnTap2 setBackgroundImage:[UIImage imageNamed:@"帖子"] forState:UIControlStateNormal];
    [_btnTap2 setTitleColor:UIColorFromRGB(TextWhiteColor) forState:UIControlStateNormal];
    [_btnTap2 setTitleColor:UIColorFromRGB(BgTitleColor) forState:UIControlStateSelected];
    [_btnTap2.titleLabel setFont:ListElevenFont];
    [_btnTap2 setTitle:@"帖子" forState:0];
    [_btnTap2 setImage:[UIImage imageNamed:@"帖子 切换 copy"] forState:UIControlStateSelected];
    [_btnTap2 setImage:[UIImage imageNamed:@"帖子 切换"] forState:UIControlStateNormal];
    [_btnTap2 addTarget:self action:@selector(tapClick:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    UIImageView *imgLine = [self createImageView];
    [imgLine setBackgroundColor:UIColor.whiteColor];
    [imgLine setFrame:CGRectMake(0, CGRectGetMaxY(_btnTap1.frame)-1, ScreenWidth, 12)];
    [ZZViewUtils cutViewRound:imgLine radius:10 byRoundingCorners:UIRectCornerTopLeft];
    [_viewMenus addSubview:imgLine];
    
    
    
    _btnTap1.selected = YES;
    _btnTap2.selected = NO;
}


-(void)tapClick:(UIButton *) btn{

    DLog(@"btn------:%@", btn);
    
    if([btn isEqual:_btnTap1]){
        _btnTap1.selected = YES;
        _btnTap2.selected = NO;
        [_btnTap1 setTintColor:UIColorFromRGB(TextWhiteColor)];
        [_btnTap2 setTintColor:UIColorFromRGB(BgTitleColor)];
        
        
        [_btnTap1 setTitleColor:UIColorFromRGB(BgTitleColor) forState:UIControlStateSelected];
        [_btnTap1 setTitleColor:UIColorFromRGB(BgTitleColor) forState:UIControlStateNormal];
        
        [_btnTap1 setImage:[UIImage imageNamed:@"素材 切换 copy"] forState:UIControlStateNormal];
        [_btnTap1 setImage:[UIImage imageNamed:@"素材 切换 copy"] forState:UIControlStateSelected];
        [self onHeaderCellItemClick:ZZHeaderTypeSucai obj:nil];
        
    }else if([btn isEqual:_btnTap2]){
        
        _btnTap1.selected = YES;
        _btnTap2.selected = YES;
        
        [_btnTap2 setTintColor:UIColorFromRGB(TextWhiteColor)];
        [_btnTap1 setTintColor:UIColorFromRGB(BgTitleColor)];
        
        [_btnTap1 setTitleColor:UIColorFromRGB(TextWhiteColor) forState:UIControlStateSelected];
        [_btnTap1 setTitleColor:UIColorFromRGB(TextWhiteColor) forState:UIControlStateNormal];
        
        [_btnTap1 setImage:[UIImage imageNamed:@"素材 切换"] forState:UIControlStateSelected];
        [_btnTap1 setImage:[UIImage imageNamed:@"素材 切换"] forState:UIControlStateNormal];
        
        [self onHeaderCellItemClick:ZZHeaderTypeTiezi obj:nil];
    }
}



@end
